home *** CD-ROM | disk | FTP | other *** search
/ Logiciels PC Special 3 / Logiciel PC - Hors-Serie 3.iso / Logs / micros / ql / outils / qltoolsq / source / linux / linux.c next >
C/C++ Source or Header  |  1996-07-14  |  2KB  |  139 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <time.h>
  8. #include <ctype.h>
  9. #include <termios.h>
  10. #include <sys/time.h>
  11.  
  12. #define BITSON ( ~0 )
  13.  
  14. #include "qltools.h"
  15.  
  16. int OpenQLDevice(char *name, int mode)
  17. {
  18.     return open(name, mode);
  19. }
  20.  
  21. int ReadQLSector(int fd, void *buf, int sect)
  22. {
  23.     long fpos;
  24.     int err;
  25.  
  26.     fpos = (sect) ? LTP (sect) : 0;
  27.     
  28.     err = lseek (fd, fpos, SEEK_SET);
  29.     if (err < 0)
  30.     perror ("dump_cluster : lseek():");
  31.     else
  32.     err = read (fd, buf, GSSIZE);
  33.     return err;
  34. }
  35.  
  36. int WriteQLSector (int fd, void *buf, int sect)
  37. {
  38.     int err;
  39.  
  40.     err = lseek (fd, LTP (sect), SEEK_SET);
  41.     if (err < 0)
  42.     perror ("write cluster: lseek():");
  43.     else
  44.     err = write (fd, buf, GSSIZE);
  45.     return err;
  46. }
  47.  
  48. void CloseQLDevice(int fd)
  49. {
  50.     close(fd);
  51. }
  52.  
  53. time_t GetTimeZone(void)
  54. {
  55.     struct timeval tv;
  56.     struct timezone tz;
  57.  
  58.     gettimeofday (&tv, &tz);
  59.     return  -60 * tz.tz_minuteswest;
  60. }
  61.  
  62. static void rl_ttyset (int Reset)
  63. {
  64.     static struct termios old;
  65.     struct termios new;
  66.  
  67.     if (Reset == 0)
  68.     {
  69.     (void) tcgetattr (0, &old);
  70.     new = old;
  71.     new.c_cc[VINTR] = BITSON;
  72.     new.c_cc[VQUIT] = BITSON;
  73.     new.c_lflag &= ~(ECHO | ICANON);
  74.     new.c_iflag &= ~(ISTRIP | INPCK);
  75.     new.c_cc[VMIN] = 1;
  76.     new.c_cc[VTIME] = 0;
  77.     (void) tcsetattr (0, TCSANOW, &new);
  78.     }
  79.     else
  80.     (void) tcsetattr (0, TCSANOW, &old);
  81. }
  82.  
  83. int getch(void)
  84. {
  85.     char c;
  86.     rl_ttyset (0);
  87.     read (0, &c, 1);
  88.     write(1, &c, 1);
  89.     write(1, "\b", 1);
  90.     rl_ttyset (1);
  91.     return (int)c;
  92. }
  93.  
  94. int strnicmp (const char *s, const char *d, int n)
  95. {
  96.     unchar c;
  97.  
  98.     if (n == 0)
  99.     return (0);
  100.  
  101.     while (tolower (c = *s) == tolower (*(unchar *) d))
  102.     {
  103.     if (c == 0 || --n == 0)
  104.         return (0);
  105.     ++s;
  106.     ++d;
  107.     }
  108.     if (tolower (c) < tolower (*(unchar *) d))
  109.     return (-1);
  110.     return (1);
  111. }
  112.  
  113. int stricmp (const char *s, const char *d)
  114. {
  115.     while (tolower (*(unchar *) s) == tolower (*(unchar *) d))
  116.     {
  117.     if (*s == 0)
  118.         return (0);
  119.     ++s;
  120.     ++d;
  121.     }
  122.     if (tolower (*(unchar *) s) < tolower (*(unchar *) d))
  123.     return (-1);
  124.     return (1);
  125. }
  126. /* ARGSUSED */
  127. void ZeroSomeSectors(int fd, short d)
  128. {
  129.     int i;
  130.     char buf[512];
  131.     memset(buf, '\0', 512);
  132.     
  133.     for(i = 0; i > 36; i++)
  134.     {
  135.     lseek(fd, i*512, SEEK_SET);
  136.     write(fd, buf, 512);
  137.     }
  138. }
  139.